﻿using Orleans;
using Pay.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pay.Model.Model;
using Pay.Dal;
using Pay.Container;
using Pay.Model.Interfaces;

namespace Pay.ServiceImplement
{
    public class RoleServiceImplement : Grain, IRoleService
    {
        public async Task<List<RoleMenuInfo>> GetMenuByRoleId(long roleId)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.GetMenuByRoleId(roleId);
        }
        public async Task<long> Add(RoleInfo model)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.Add(model);
        }

        public async  Task<bool> Delete(long roleId)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.Delete(roleId);
        }

        public async Task<List<RoleInfo>> GetRoleByType(int type)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.GetRoleByType(type);
        }

        public async Task<IPagedOutput<RoleInfo>> GetPage(string searchWord, DateTime? timeBegin = null, DateTime? timeEnd = null, int offset = 10, int rows = 1)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.GetPage(searchWord, timeBegin, timeEnd, offset, rows);
        }
        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <returns></returns>
        public async Task<List<MenuInfo>> GetAllMenu()
        {
            var instance = LocManager.Resolve<IRoleDal>();
           return await instance.GetAllMenu();
        }

        public async Task<long> Add(RoleMenuInfo model)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await  instance.Add(model);
        }

        public async Task<RoleInfo> GetRoleById(long id)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.GetRoleById(id);
        }

        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<bool> Update(RoleInfo model)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await  instance.Update(model);
        }
        /// <summary>
        /// 更加roleid 删除menu对应关系
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public async Task<bool> DeleteMenuByRoleId(long roleId)
        {
            var instance = LocManager.Resolve<IRoleDal>();
            return await instance.DeleteMenuByRoleId(roleId);
        }
    }
}
